home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 44 / Amiga Format CD44 (1999-08-26)(Future Publishing)(GB)(Track 1 of 3)[!][issue 1999-10].iso / -in_the_mag- / basics / amos / moreuselssprgs.lha / VecRotSolidJens.AMOS / VecRotSolidJens.amosSourceCode
AMOS Source Code  |  1997-04-18  |  4KB  |  148 lines

  1. ' ************************************* Commands used: 
  2. ' *                                   * Vec Rot Pos        Blitter Clear 
  3. ' *           Amcaf Examples          * Vec Rot Angles     =Qsin 
  4. ' *     Vector Rotate Solid V1.1      * Vec Rot Precalc
  5. ' *      Written by Chris Hodges      * =Vec Rot X 
  6. ' *                                   * =Vec Rot Y 
  7. ' ************************************* =Vec Rot Z 
  8. '                          
  9. ' Kill the mouse 
  10. Hide 
  11. ' Setup a nice little screen with double buffering 
  12. Screen Open 0,320,256,8,Lowres
  13. Curs Off : Flash Off : Paper 0 : Pen 1 : Cls 
  14. Palette 0,$F44,$4F4,$FF4,$44F,$F4F,$4FF
  15. Double Buffer 
  16. Autoback 0
  17. ' Read out, how many coords are used.
  18. Restore COORDS
  19. Read NUMCO
  20. ' Dim one field to keep these coords, and a second for the rotated.
  21. Dim CO(NUMCO,2),RC(NUMCO,2)
  22. ' Now read all coords in.
  23. For A=1 To NUMCO
  24.   Read CO(A,0),CO(A,1),CO(A,2)
  25. Next 
  26. ' Then, get the number of shapes the object consists of. 
  27. Restore SHAPES
  28. Read NUMLI
  29. ' Dim a field to hold the four coords. 
  30. Dim LI(NUMLI,4)
  31. ' Get the datas. 
  32. For A=1 To NUMLI
  33.   Read LI(A,0),LI(A,1),LI(A,2),LI(A,3)
  34.   Read LI(A,4)
  35. Next 
  36. ' This is new: An string array is used for sorting!  
  37. Dim SOAR$(NUMLI-1)
  38. ' Set the three angles. Remember that these are non standard angles, 
  39. ' one full rotation is at 1024, not 360! 
  40. AX=0 : AY=512 : AZ=128
  41. Repeat 
  42.   ' Start clearing bitplane 0. 
  43.    Extension_8_121C 0,0
  44.   ' While the blitter is working, use the time to calculate the rotations. 
  45.   ' Move and set the angles. 
  46.   Add AX,5
  47.   Add AY,8
  48.   Add AZ,11
  49.    Extension_8_1138 AX,AY,AZ
  50.   ' Calculate the distances by using a sine-function and the three angles. 
  51.   POSX= Extension_8_1106(AX,300)
  52.   POSY= Extension_8_1106(AY,300)
  53.   POSZ= Extension_8_1106(AZ,500)+1500
  54.   ' Set the camera positions.
  55.    Extension_8_1122 POSX,POSY,POSZ
  56.   ' Now it's time to compute the matrix. 
  57.    Extension_8_1152 
  58.   ' Clear bitplane 1 
  59.    Extension_8_121C 0,1
  60.   ' So let's rotate all coordinates of the field CO()
  61.   For A=1 To NUMCO
  62.     ' Note: You only have to use the vec rot function with parameters once.
  63.     RC(A,0)= Extension_8_1168(CO(A,0),CO(A,1),CO(A,2))+160
  64.     RC(A,1)= Extension_8_1184 +128
  65.     RC(A,2)= Extension_8_11C4 
  66.   Next 
  67.   ' Clear bitplane 2 
  68.    Extension_8_121C 0,2
  69.   ' It's time to finally get the polygons to the screen! 
  70.   For A=1 To NUMLI
  71.     ' Get the four coordinates pairs.  
  72.     C1=LI(A,0) : C2=LI(A,1) : C3=LI(A,2) : C4=LI(A,3)
  73.     CO=LI(A,4)
  74.     ' Get the distance of the polygon
  75.     Z=(RC(C1,2)+RC(C2,2)+RC(C3,2)+RC(C4,2))/4
  76.     ' Create a string that contains all the data.
  77.     SOAR$(A-1)= Extension_8_08D2(-Z)+ Extension_8_08D2(RC(C1,0))+ Extension_8_08D2(RC(C1,1))+ Extension_8_08D2(RC(C2,0))+ Extension_8_08D2(RC(C2,1))
  78.     SOAR$(A-1)=SOAR$(A-1)+ Extension_8_08D2(RC(C3,0))+ Extension_8_08D2(RC(C3,1))+ Extension_8_08D2(RC(C4,0))+ Extension_8_08D2(RC(C4,1))+ Extension_8_08C4(CO)
  79.   Next 
  80.   ' Sort the array 
  81.   Sort SOAR$(0)
  82.   For A=1 To NUMLI
  83.     ' Get the rotated coordinates
  84.     AD=Varptr(SOAR$(A-1))
  85.     X1=Leek(AD+4) : Y1=Leek(AD+8)
  86.     X2=Leek(AD+12) : Y2=Leek(AD+16)
  87.     X3=Leek(AD+20) : Y3=Leek(AD+24)
  88.     X4=Leek(AD+28) : Y4=Leek(AD+32)
  89.     CO=Deek(AD+36)
  90.     ' Use some maths, to see if the plane faces into the camera or into
  91.     ' the back. This formula works ONLY, if the polygon is drawn 
  92.     ' anticlockwise!   
  93.     DI=(X3-X1)*(Y2-Y1)-(X2-X1)*(Y3-Y1)
  94.     If DI<0
  95.       ' Draw the polygons in colour CO 
  96.       Ink CO
  97.       Polygon X1,Y1 To X2,Y2 To X3,Y3 To X4,Y4
  98.     End If 
  99.   Next 
  100.   ' Swap the screens to bring the object to view.
  101.   Screen Swap 
  102.   Wait Vbl 
  103. Until Inkey$=Chr$(27) or Mouse Key<>0
  104. Screen Close 0
  105. End 
  106. '  1_____2   
  107. ' 5/____/| 
  108. ' | |  |6| 
  109. ' |4|__|_|3  
  110. ' |/___|/
  111. ' 8    7 
  112. COORDS:
  113.   Data 16
  114. ' CUBE 
  115.   Data -100,-100,-100
  116.   Data 100,-100,-100
  117.   Data 100,-100,100
  118.   Data -100,-100,100
  119.   Data -100,100,-100
  120.   Data 100,100,-100
  121.   Data 100,100,100
  122.   Data -100,100,100
  123.  
  124.   Data -200,-25,-25
  125.   Data -100,-25,-25
  126.   Data -100,-25,25
  127.   Data -200,-25,25
  128.   Data -200,25,-25
  129.   Data -100,25,-25
  130.   Data -100,25,25
  131.   Data -200,25,25
  132.  
  133. SHAPES:
  134.   Data 11
  135. ' All lines are drawn in anticlockwise.
  136.   Data 1,2,6,5,1
  137.   Data 4,3,2,1,2
  138.   Data 2,3,7,6,3
  139.   Data 3,4,8,7,4
  140.   Data 4,1,5,8,5
  141.   Data 6,7,8,5,6
  142.  
  143.   Data 9,10,14,13,6
  144.   Data 12,11,10,9,1
  145. '  Data 10,11,15,14,2
  146.   Data 11,12,16,15,3
  147.   Data 12,9,13,16,5
  148.   Data 14,15,16,13,4